﻿<?php
    require_once 'db.php';
    
    $type = "user";
    if (isset($_GET['type']))
    {
        $type = $_GET['type'];
    }
    
    if ($type == "user")
    {
        $sql = "select userid, username, createtime from users;";
        $title = "用户信息";
    }
    elseif ($type == "log")
    {
        $sql = "select * from op_log;";
        $title = "访问日志";
    }
    else
    {
        echo "Donot support this type: $type";
        exit(0);
    }
    $result = $db->fetchAll($sql); 
?>
<html>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type" /> 
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <link rel="stylesheet" type="text/css" href="css/open.css">
    </head>
    <body>
        <H1><?php echo $title; ?></H1>
        <div id="content" class="grid-view">
        <table width="100%" border="1" class="items">
            <tr>
            <?php
                foreach(array_keys($result[0]) as $key)
                {
                    echo "<th>$key</th>";
                }
            ?>
            </tr>
            <?php
                foreach($result as $row)
                {
            ?>
            <tr class="odd">
                <?php
                    foreach(array_values($row) as $value)
                    {
                        echo "<td>$value</td>";
                    }
                ?>
            </tr>
            <?php
                }
            ?>
        </table>
        </div>
    </body>
</html>